<?php

use Illuminate\Database\Seeder;
use App\Models\Movie;
use App\Models\Category;
class CategoryMovieTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $movies = Movie::all();
        $categories = Category::all();

        foreach($movies as $movie) {
            $movie->categories()->sync($categories->random(rand(2,4))->pluck('id'));
        }
    }
}
